﻿using System.Data;
using Sanelib.DataView;
using WebApp.ModelService;

namespace WebApp.Services.Impl
{
    public class ReportDataProvider : IReportDataProvider
    {
        private readonly IMemberModelService _memberModelService;

        public ReportDataProvider(IMemberModelService memberModelService)
        {
            _memberModelService = memberModelService;
        }


        public DataTable GetMemberDetails(SearchSpecification searchSpecification)
        {
            var data = new DataTable();

            data.Columns.Add("Tag Id");            
            data.Columns.Add("Code");
            data.Columns.Add("Name");
            data.Columns.Add("DateOfBirth");
            data.Columns.Add("Address");
            data.Columns.Add("Email");
            data.Columns.Add("Mobile");

            var members = _memberModelService.GetPageBySpecification(searchSpecification);
            searchSpecification.PageSize = 1000;
            searchSpecification.Page = 1;

            while (members.Items.Count > 0)
            {
                foreach (var member in members.Items)
                {
                    data.Rows.Add(member.TagId, member.Code, member.Name, member.DateOfBirth, member.Address, member.Email, member.Mobile);
                }
                searchSpecification.Page ++;
                members = _memberModelService.GetPageBySpecification(searchSpecification);
            }

            return data;
        }      
    }
}